package com.gitee.candy.encry;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class EncryptURLUtils {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String url = "https://baidu.com";
        String charset = "utf-8";
        String encode = encode(url, charset);
        System.out.println(encode);
        String decode = decode(encode, charset);// GBK解码
        System.out.println(decode);
    }

    public static String encode(String url, String charset) throws UnsupportedEncodingException {
        return URLEncoder.encode(url, charset);
    }

    public static String decode(String urlEncode, String charset) throws UnsupportedEncodingException {
        return URLDecoder.decode(urlEncode, charset);
    }
}
